<template>
  <div class="search-list">
    <transition-group name="list" tag="ul">
      <li
        class="search-item"
        v-for="item in searchs"
        :key="item"
        @click="clickHistory(item)"
      >
        <span class="text">{{ item }}</span>
        <span class="icon-box">
          <i class="icon" @click.stop="deleteHistory(item)">&#xe656;</i>
        </span>
      </li>
    </transition-group>
  </div>
</template>

<script>
export default {
  props: {
    searchs: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  methods: {
    deleteHistory(item) {
      this.$store.dispatch("deleteHistory", item);
      // this.$store.commit('removeHistory',item)
    },
    clickHistory(item) {
      this.$emit("clickHistory", item);
    },
  },
};
</script>

<style lang="less">
.search-list {
  .search-item {
    display: flex;
    align-items: center;
    height: 40px;
    overflow: hidden;

    &.list-enter-active,
    &.list-leave-active {
      transition: all 0.1s;
    }

    &.list-enter,
    &.list-leave-to {
      height: 0;
    }

    .text {
      flex: 1;
      color: hsla(0, 0%, 100%, 0.5);
    }

    .icon-box {
      .icon {
        font-size: 18px;
        color: hsla(0, 0%, 100%, 0.3);
      }
    }
  }
}
</style>